package org.example.controller;

import jakarta.annotation.Resource;
import org.example.pojo.Task;
import org.example.service.TaskService;
import org.example.utils.R;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * @Description: 任务的核验
 * @Author:曹震
 * @Date: 2024/11/27 11:44
 */
@CrossOrigin
@RestController
@RequestMapping("task")
public class TaskController {
    @Resource
    private TaskService service;
    @GetMapping("check")
    //查询还在那些在审核中的任务
    public R checkResponse(@RequestParam(defaultValue = "1") Integer currentPage,
                           @RequestParam(defaultValue = "10")Integer pageSize){

        R task = service.findTask(currentPage, pageSize);
       return task;
    }
    //查询所有的页面
    @GetMapping("select")
    public R selectTask(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) Integer taskStatus,
            @RequestParam(required = false) String requesterName,
            @RequestParam(required = false) Integer taskCategory,
            @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate createdAtStart,
            @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate createdAtEnd) {
        // 进行分页和查询调用
        R r = service.listTask(currentPage, pageSize, requesterName,taskStatus, taskCategory, createdAtStart, createdAtEnd);
        return r;
    }



    //通过核验
    @PostMapping("pass")
        public R passResponse(@RequestBody Task task){
            R r = service.passTask(task.getTaskId());
            return r;
        }
        //不通过核验,返回理由
    @PostMapping("refuse")
    public R refuseResponse(@RequestBody Task task){
        Integer taskId = task.getTaskId();
        //拒绝理由
        String objection = task.getObjection();
        R r = service.refuseTask(taskId, objection);
        return r;
    }
}
